package com.zhejiangzhengyuan.municipal_common.mapper;

import com.zhejiangzhengyuan.municipal_common.entity.Action;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhejiangzhengyuan.municipal_common.entity.vo.ActionTitle;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 服务API--行为表，提供两种权限比对方式：1、基于权限点；2、基于URL Mapper 接口
 *
 * @author linju
 * @since 2019-11-22
 */
@Repository
public interface ActionMapper extends BaseMapper<Action> {

  // 用于JWT校验
  //根据permission表查询
  List<Action> findPermissionActionBySubjectIdByUrlAction(@Param("id") Long id, @Param("url") String url);
  //根据role表查询
  List<Action> findRoleActionBySubjectIdByUrlAction(@Param("id") Long id, @Param("url") String url);





  @Select("select  ram.action_id from role r,role_action_mapping ram\n" +
          "where r.id=ram.role_id and r.id=#{rid}")
    List<Long> selectActionIdByRoleId(@Param("rid") Long rid);


  @Select("select * from action")
    List<ActionTitle> selectAction();
  @Select("select a.pattern_url from action a,subject s, role r,subject_role_mapping srm,role_action_mapping ram\n" +
          "where a.id=ram.action_id and r.id=ram.role_id and s.id=srm.subject_id and r.id=srm.role_id and s.id=#{sid}")
    List<String> selectUrlBySubjectId(@Param("sid")Long id);
}
